
import Vue from "vue";
import VueRouter from "vue-router";
Vue.use(VueRouter)
const routes = [
  { name: 'NotFound', path: '*', hidden: true, component: () => import('../components/NotFound.vue'), },//404
  { path: '/', redirect: '/login', hidden: true, name: '首页', },
  { path: '/login', hidden: true, component: () => import('../components/Login.vue'), },
  {
    name: '学生管理', path: '/home', iconClass: 'fa fa-users', component: () => import('../components/Home.vue'),
    redirect: '/home/student',
    children: [
      {
        path: '/home/student',
        name: '学生列表',
        iconClass: 'fa fa-list',
        component: () => import('@/components/students/StudentList')
      },
      {
        path: '/home/info',
        name: '信息列表',
        iconClass: 'fa fa-list-alt',
        component: () => import('@/components/students/InfoList')
      },
      {
        path: '/home/infos',
        name: '信息管理',
        iconClass: 'fa fa-list-alt',
        component: () => import('@/components/students/InfoLists')
      },
      {
        path: '/home/work',
        name: '作业列表',
        iconClass: 'fa fa-list-ul',
        component: () => import('@/components/students/WorkList')
      },
      {
        path: '/home/works',
        name: '作业管理',
        iconClass: 'fa fa-th-list',
        component: () => import('@/components/students/WorkMent')
      }
    ]
  },
  {
    path: '/data',
    name: '数据分析',
    iconClass: 'fa fa-bar-chart',
    component: () => import('@/components/Home'),
    redirect: '/data/dataview',
    children: [
      {
        path: '/data/dataview',
        name: '数据概览',
        iconClass: 'fa fa-line-chart',
        component: () => import('@/components/dataAnalysis/DataView')
      },
      {
        path: '/data/mapview',
        name: '地图概览',
        iconClass: 'fa fa-line-chart',
        component: () => import('@/components/dataAnalysis/MapView')
      },
      {
        path: '/data/travel',
        name: '旅游地图',
        iconClass: 'fa fa-line-chart',
        component: () => import('@/components/dataAnalysis/TravelMap')
      },
      {
        path: '/data/score',
        name: '分数地图',
        iconClass: 'fa fa-line-chart',
        component: () => import('@/components/dataAnalysis/ScoreMap')
      }
    ]
  },
  {
    path: '/users',
    name: '用户中心',
    iconClass: 'fa fa-user',
    component: () => import('@/components/Home'),
    children: [
      {
        path: '/users/user',
        name: '权限管理',
        iconClass: 'fa fa-user',
        component: () => import('@/components/users/User')
      }
    ]
  }
]

// 3. 创建 router 实例，然后传 `routes` 配置
// 你还可以传别的配置参数, 不过先这么简单着吧。
const router = new VueRouter({
  mode: 'history',
  routes // (缩写) 相当于 routes: routes
})
// 路由导航守卫
router.beforeEach((to, from, next) => {
  if (!localStorage.getItem('username')) {
    if (to.path !== '/login') {
      next('/login')
    } else {
      next()
    }
  }
  next()
})
export default router
